package org.edu.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name="ADDRESS", catalog="SCHOOL")
public class Address implements Serializable{

	private static final long serialVersionUID = 1L;
	private Long address_id;
	private User userAdress;
	private String address_detail;
	private String city;
	private String zip_postcode;

	@Id
	@Column(name="ADDRESS_ID", unique=true, nullable=false)
	@GeneratedValue(generator="gen")
	@GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="userAdress"))
	public Long getAddress_id() {
		return address_id;
	}

	public void setAddress_id(Long address_id) {
		this.address_id = address_id;
	}
	
	@OneToOne
	@PrimaryKeyJoinColumn
	public User getUserAdress() {
		return userAdress;
	}

	public void setUserAdress(User userAdress) {
		this.userAdress = userAdress;
		this.userAdress.setAddress(this);
	}

	@Column(name = "ADDRESS_DETAIL", length = 300)
	public String getAddress_detail() {
		return address_detail;
	}

	public void setAddress_detail(String address_detail) {
		this.address_detail = address_detail;
	}

	@Column(name = "CITY", length = 20)
	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	@Column(name = "ZIP_POSTCODE", length = 10)
	public String getZip_postcode() {
		return zip_postcode;
	}

	public void setZip_postcode(String zip_postcode) {
		this.zip_postcode = zip_postcode;
	}

	public Address() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((address_detail == null) ? 0 : address_detail.hashCode());
		result = prime * result
				+ ((address_id == null) ? 0 : address_id.hashCode());
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result
				+ ((zip_postcode == null) ? 0 : zip_postcode.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Address other = (Address) obj;
		if (address_detail == null) {
			if (other.address_detail != null)
				return false;
		} else if (!address_detail.equals(other.address_detail))
			return false;
		if (address_id == null) {
			if (other.address_id != null)
				return false;
		} else if (!address_id.equals(other.address_id))
			return false;
		if (city == null) {
			if (other.city != null)
				return false;
		} else if (!city.equals(other.city))
			return false;
		if (zip_postcode == null) {
			if (other.zip_postcode != null)
				return false;
		} else if (!zip_postcode.equals(other.zip_postcode))
			return false;
		return true;
	}
	
}
